<template>
  <base-layout
     :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel  @search="search" :show-search-button="true" :showAddButton="true" @insert="handleDataInsert" labelWidth="100" :left="true">
        <el-form-item label="业务类型名称:">
          <el-input v-model="filters.busname" clearable style="width: 200px" placeholder="名称" />
        </el-form-item>
        <el-form-item label="业务类型代码:">
          <el-input v-model="filters.busCode" clearable style="width: 200px" placeholder="代码" />
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
          <el-button size="small" round @click="editSubmit(row)">{{row.status == "1" ? '禁用' : '启用'}}</el-button>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <el-form :model="addForm" label-width="80px" ref="addForm">
        <el-form-item label="名称" prop="busname">
          <el-input v-model="addForm.busname"  ></el-input>
        </el-form-item>
        <el-form-item label="代码" prop="busCode">
          <el-input v-model="addForm.busCode"  ></el-input>
        </el-form-item>

        <el-form-item label="备注">
          <el-input type="textarea" v-model="addForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center;">
        <el-button round size="small" @click.native="dialogVisible = false">取消</el-button>
        <el-button round size="small" type="primary" @click.native="addSubmit">提交</el-button>
      </div>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
// import DialogDataForm from './components/DialogDataForm'
import { getBusTypePage,updateBussinesType,addBussinesType } from '@/api/utilsapi'

export default {
  name: 'businesstype',
  components: {  },
  mixins: [
    baseMixin({
      idName: 'id',
      findData: getBusTypePage,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      tableColumnAttributes: [
        { name: '业务类型名称', value: 'busname' },
        { name: '业务类型代码', value: 'busCode' },
        { name: '状态', value: 'status' , formatter:this.formatStatus},
        { name: '创建时间', value: 'createtime'},
        { name: '备注', value: 'remark'},
      ],
      filters: {
        busname: '',
        busCode:''
      },
      addForm: {
        busname: '',
        busCode: '',
        remark: ''
      }
    }
  },
  methods: {
    search(form){
      let para = {
        start: 0,
        pageSize: 10,
        busname: this.filters.busname,
        busCode: this.filters.busCode
      };
      this.searchOptions = para;
      this.setTableData()
    },
    formatStatus: function (row, column) {
      return row.status == "1" ? '正常' : row.status == "0" ? '禁用' : '未知';
    },
    editSubmit(row) {
      this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
        let para = row
        para.status = para.status == "1" ? "0" : "1";
        updateBussinesType(para).then((res) => {
          this.resultSuccess(res)
        });
      });
    },
    //新增
    addSubmit: function () {
        this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
          let para = Object.assign({}, this.addForm);
          addBussinesType(para).then((datas) => {
            this.resultSuccess(datas)
          }).catch(function (error) {
            console.log(error);
          });
        });
    }
  }
}
</script>
